package greedy;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: 海琳琦
 * @Date: 2022/2/28 20:02
 * https://leetcode-cn.com/problems/partition-labels/
 */
public class PartitionLabels {

    public List<Integer> partitionLabels(String s) {
        int[] arr = new int[26];
        List<Integer> result = new ArrayList<>();
        //存放出现字符的最大索引
        for (int i = 0; i < s.length(); i++) {
            arr[s.charAt(i) - 'a'] = i;
        }
        int left = 0;
        int right = 0;
        for (int i = 0; i < s.length(); i++) {
            right = Math.max(right, arr[s.charAt(i) - 'a']);
            if (i == right) {
                result.add(right - left + 1);
                left = i + 1;
            }
        }
        return result;
    }

    public static void main(String[] args) {

    }
}
